home *** CD-ROM | disk | FTP | other *** search
- <xsl:stylesheet
- version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:wp="http://schemas.microsoft.com/WebPart/v2">
- <xsl:output
- method="xml"
- indent="no"
- omit-xml-declaration="yes" />
- <xsl:strip-space elements="*" />
-
- <xsl:param name="whoHasCDATAs"></xsl:param>
- <xsl:param name="tabChar" select="' '"/>
- <xsl:param name="preindent" select="''"/>
-
- <!--
- a very simple pretty-printer for XML;
- once upon a time, the XML DOM did something
- like this when the Save() method was called;
- the '
' business below is a newline
- -->
-
- <xsl:template match="*">
- <xsl:call-template name="standard"/>
- </xsl:template>
-
- <xsl:template name="standard">
- <xsl:variable name="haskids" select="count(*) > 0" />
- <xsl:call-template name="indent" />
- <xsl:choose>
- <xsl:when test="count(*|comment()|processing-instruction()|text()) > 0">
- <xsl:copy>
- <xsl:copy-of select="@*" />
- <xsl:apply-templates />
- <xsl:if test="$haskids">
- <xsl:call-template name="indent" />
- </xsl:if>
- </xsl:copy>
- </xsl:when>
- <xsl:otherwise>
- <xsl:copy>
- <xsl:copy-of select="@*" />
- </xsl:copy>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
-
- <xsl:template match="wp:DataQuery|wp:XSL|wp:Content">
-
- <xsl:choose>
- <xsl:when test="contains( $whoHasCDATAs,local-name() )">
- <xsl:variable name="haskids" select="count(*) > 0" />
- <xsl:value-of select="'
'" />
- <xsl:copy>
- <xsl:copy-of select="@*" />
- <xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
- <xsl:value-of select="." disable-output-escaping="yes"/>
- <xsl:text disable-output-escaping="yes">]]></xsl:text>
- </xsl:copy>
- </xsl:when>
- <xsl:otherwise>
- <xsl:call-template name="standard"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
-
- <xsl:template match="a[img]">
- <xsl:call-template name="indent" />
- <xsl:copy>
- <xsl:copy-of select="@*" />
- <xsl:apply-templates mode="noindent" />
- </xsl:copy>
- </xsl:template>
-
- <xsl:template match="*" mode="noindent">
- <xsl:copy>
- <xsl:copy-of select="@*"/>
- <xsl:apply-templates mode="noindent" />
- </xsl:copy>
- </xsl:template>
-
- <!--
- We strip the crs off the end of the text
- nodes. What happens is that the text nodes include
- all the whitespace after the last printable char. Thus
- each time a text node is followed by a tag (which is preceded
- by a CR, then the CR becomes part of the text node on teh
- next iteration
- -->
- <xsl:template name="strip-crs">
- <xsl:param name="text"/>
- <xsl:variable name="sp" select="' '" />
- <xsl:variable name="tab" select="' '" />
- <xsl:variable name="cr" select="'
'" />
- <xsl:variable name="lf" select="'
'" />
- <xsl:choose>
- <xsl:when test="
- substring($text,string-length($text)) = $cr
- or substring($text,string-length($text)) = $lf
- or substring($text,string-length($text)) = $sp
- or substring($text,string-length($text)) = $tab">
- <xsl:variable name="result">
- <xsl:call-template name="strip-crs">
- <xsl:with-param name="text" select="substring($text,1,string-length($text)-1)"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:value-of select="$result"/><xsl:text> </xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$text"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
-
- <xsl:template match="text()">
- <xsl:call-template name="strip-crs">
- <xsl:with-param name="text"><xsl:value-of select="."/></xsl:with-param>
- </xsl:call-template>
- </xsl:template>
-
- <xsl:template match="comment()|processing-instruction()">
- <xsl:call-template name="indent" />
- <xsl:copy/>
- </xsl:template>
-
- <xsl:template name="indent">
- <xsl:value-of select="'
'" />
- <xsl:for-each select="ancestor::*">
- <xsl:value-of select="$preindent" /><xsl:value-of select="$tabChar" />
- </xsl:for-each>
- </xsl:template>
-
- </xsl:stylesheet>
-